package com.ymttest.business.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.ymatou.riskcontrol.api.parameter.OrderItem;
import com.ymatou.riskcontrol.api.parameter.RiskDetailBean;
import com.ymatou.riskcontrol.api.parameter.RiskEsblishBean;
import com.ymatou.riskcontrol.api.service.RiskDetailCall;
import com.ymatou.riskcontrol.api.service.RiskEsblishCall;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.TestDataManager;

/************************************************************************************
 * @File name :RiskCallService.java
 * @Author : zhouyi
 * @Date : 2015年8月10日
 * @Copyright : 洋码头
 ************************************************************************************/
public class RiskCallService {
	public static JSONObject getRiskDetail(String orderid) {
		try {
			RiskDetailBean rdb = new RiskDetailBean();
			rdb.setOrderId(orderid);
			RiskDetailCall rdc = new RiskDetailCall();
			rdc.setData(false,rdb);
			rdc.callService();
			Logger.debug(rdc.getEntityString());
			Logger.debug(rdc.getReturnData());
			return rdc.getData();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @return
	 */
	public static Map getRiskEsblish() {
		Map m = new HashMap();
		try {
			RiskEsblishBean reb = new RiskEsblishBean();
			RiskEsblishCall rec = new RiskEsblishCall();
			m.put("OrderId", TestDataManager.getClientpaymentId().substring(5, 13));
			m.put("UserId", TestDataManager.getClientpaymentId().substring(7, 13));
			m.put("ActivityId", TestDataManager.getClientpaymentId().substring(9, 13));
			m.put("SellerId", TestDataManager.getClientpaymentId().substring(9, 13));
			m.put("ThirdCategoryId", TestDataManager.getClientpaymentId().substring(5, 13));
			m.put("CatalogId", TestDataManager.getRandomUUID().toString());
			m.put("ProductId", TestDataManager.getRandomUUID().toString());
			m.put("TotalPrice", 10);
			int orderid = Integer.valueOf(m.get("OrderId").toString());
			int userid = Integer.valueOf(m.get("UserId").toString());
			int activityId = Integer.valueOf(m.get("ActivityId").toString());
			int SellerId = Integer.valueOf(m.get("SellerId").toString());
			int ThirdPartTradingId = Integer.valueOf(TestDataManager.getClientpaymentId().substring(5, 13));
			BigDecimal TotalPrice = new BigDecimal(m.get("TotalPrice").toString());
			String TradingId = TestDataManager.getRandomUUID().toString();
			// 一个订单，单价等于总价
			BigDecimal OrderPrice = TotalPrice;
			String catalogId = m.get("CatalogId").toString();
			// set orderitem
			ArrayList<OrderItem> loi = new ArrayList<OrderItem>();
			OrderItem oi = new OrderItem();
			String productId = m.get("ProductId").toString();
			oi.setProductId(productId);
			oi.setActivityId(activityId);
			oi.setProductNum(1);
			oi.setCatalogId(catalogId);
			oi.setProductPrice(TotalPrice);
			loi.add(oi);
			reb.setOrderItems(loi);
			// other
			reb.setUserId(userid);
			reb.setOrderId(orderid);
			String CouponBatchId = TestDataManager.getRandomUUID().toString();
			reb.setCouponBatchId(CouponBatchId);
			String CouponId = TestDataManager.getRandomUUID().toString();
			reb.setCouponId(CouponId);
			String DeviceId = TestDataManager.getRandomUUID().toString();
			reb.setDeviceId(DeviceId);
			BigDecimal GiftAmount = new BigDecimal(1);
			reb.setGiftAmount(GiftAmount);
			reb.setIp("127.0.0.1");
			String Mobile = TestDataManager.getPhoneNum();
			reb.setMobile(Mobile);
			reb.setOrderPrice(OrderPrice);
			String PayerId = TestDataManager.getRandomUUID().toString();
			reb.setPayerId(PayerId);
			reb.setPayType("PayType");
			String RecipientMobile = TestDataManager.getPhoneNum();
			reb.setRecipientMobile(RecipientMobile);
			reb.setSellerId(SellerId);
			reb.setSellerName("自动化测试SellerName");
			reb.setUserName("UserName");
			reb.setThirdPartTradingId(String.valueOf(ThirdPartTradingId));
			reb.setTradingId(TradingId);
			rec.setData(false,reb);
			rec.callService();
			m.put("TradingId", TradingId);
			m.put("PayerId", PayerId);
			m.put("ThirdPartTradingId", ThirdPartTradingId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return m;
	}

	/**
	 * @param m
	 * @return
	 */
	public static Map getRiskEsblish(Map m) {
		try {
			RiskEsblishBean reb = new RiskEsblishBean();
			RiskEsblishCall rec = new RiskEsblishCall();
			// m.put("OrderId",
			// TestDataManager.getClientpaymentId().substring(6, 14));
			// m.put("UserId", TestDataManager.getClientpaymentId().substring(8,
			// 14));
			// m.put("ActivityId",
			// TestDataManager.getClientpaymentId().substring(10, 14));
			// m.put("SellerId",
			// TestDataManager.getClientpaymentId().substring(10, 14));
			// m.put("ThirdCategoryId",
			// TestDataManager.getClientpaymentId().substring(6, 14));
			// m.put("CatalogId", TestDataManager.getRandomUUID().toString());
			// m.put("ProductId", TestDataManager.getRandomUUID().toString());
			// m.put("TotalPrice", 10);
			int orderid = Integer.valueOf(m.get("OrderId").toString());
			int userid = Integer.valueOf(m.get("UserId").toString());
			int activityId = Integer.valueOf(m.get("ActivityId").toString());
			int SellerId = Integer.valueOf(m.get("SellerId").toString());
			int ThirdPartTradingId = Integer.valueOf(TestDataManager.getClientpaymentId().substring(6, 14));
			BigDecimal TotalPrice = new BigDecimal(m.get("TotalPrice").toString());
			String TradingId = TestDataManager.getRandomUUID().toString();
			// 一个订单，单价等于总价
			BigDecimal OrderPrice = TotalPrice;
			String catalogId = m.get("CatalogId").toString();
			// set orderitem
			ArrayList<OrderItem> loi = new ArrayList<OrderItem>();
			OrderItem oi = new OrderItem();
			String productId = m.get("ProductId").toString();
			oi.setProductId(productId);
			oi.setActivityId(activityId);
			oi.setProductNum(1);
			oi.setCatalogId(catalogId);
			oi.setProductPrice(TotalPrice);
			loi.add(oi);
			reb.setOrderItems(loi);
			// other
			reb.setUserId(userid);
			reb.setOrderId(orderid);
			String CouponBatchId = TestDataManager.getRandomUUID().toString();
			reb.setCouponBatchId(CouponBatchId);
			String CouponId = TestDataManager.getRandomUUID().toString();
			reb.setCouponId(CouponId);
			String DeviceId = TestDataManager.getRandomUUID().toString();
			reb.setDeviceId(DeviceId);
			BigDecimal GiftAmount = new BigDecimal(1);
			reb.setGiftAmount(GiftAmount);
			reb.setIp("127.0.0.1");
			String Mobile = TestDataManager.getPhoneNum();
			reb.setMobile(Mobile);
			reb.setOrderPrice(OrderPrice);
			String PayerId = TestDataManager.getRandomUUID().toString();
			reb.setPayerId(PayerId);
			reb.setPayType("PayType");
			String RecipientMobile = TestDataManager.getPhoneNum();
			reb.setRecipientMobile(RecipientMobile);
			reb.setSellerId(SellerId);
			reb.setSellerName("自动化测试SellerName");
			reb.setUserName("UserName");
			reb.setThirdPartTradingId(String.valueOf(ThirdPartTradingId));
			reb.setTradingId(TradingId);
			rec.setData(false,reb);
			rec.callService();
			m.put("TradingId", TradingId);
			m.put("PayerId", PayerId);
			m.put("ThirdPartTradingId", ThirdPartTradingId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return m;
	}
}
